/*
*
==============================================================================
*  Name        : 
*  Part of     : Omen Game Engine
*  Description : 
*  Version     : 1.0
*
*  Copyright (c) 2013 Lauri Kortevaara.
* 
==============================================================================
*/

#define OMEN_SOURCE 1

/// Omen Headers
#include <OmenUtils.h>

/// STL Headers
#include <sstream>

using namespace Omen;

///
/// <summary>Parses the given string and returns a x,y,z Omen::Vector3d vector out of it</summary>
///
OMEN_API void getFloatsVector( const std::wstring& str, std::vector<Omen::Float>& floats )
{
    std::wstring temp = str.substr( str.find_first_not_of(L" ") );
    temp = temp.substr( 0, temp.find_last_not_of(L" ")+1 );
    std::wstringstream ss( str );
    std::wstring field;

    unsigned int fpos = 0;
    while (!temp.empty())
    {
        // Remove empty spaces in the beginning of the string
        temp = temp.substr( temp.find_first_not_of(L" ") );

        std::string::size_type first_delim = temp.find_first_of(L" ");
        if( first_delim != std::wstring::npos )
        {
            std::string::size_type first_value_char = temp.find_first_not_of(L" ",first_delim);
            field = temp.substr( 0,first_value_char-1 );
            temp = temp.substr( temp.find_first_of(L" ") + 1 );
        }
        else
        {
            field = temp;
            temp = L"";
        }
            
        std::wstringstream fs( field );
        Omen::Float f = 0.0;  // (default value is 0.0)
        fs >> f;

        floats.push_back(f);

        fpos++;
    }
}

///
/// <summary>Parses the given string and returns a x,y,z Omen::Vector3d vector out of it</summary>
///
OMEN_API void getLongsVector( const std::wstring& str, std::vector<unsigned long>& longs )
{
    std::wstringstream ss( str );
    std::wstring field;

    unsigned int fpos = 0;
    while (std::getline( ss, field, L' ' ))
    {
        std::wstringstream fs( field );
        unsigned long f = 0;  // (default value is 0.0)
        fs >> f;

        longs.push_back(f);

        fpos++;
    }
}

/// EOF